//package com.hzeport.bgs22emduty;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.hzeport.bgs22emduty.entity.DutyScheduleInfo;
//import com.hzeport.bgs22emduty.entity.ParamSmsTemplate;
//import com.hzeport.bgs22emduty.enums.DeleteFlagEnum;
//import com.xxl.job.core.biz.model.ReturnT;
//import com.xxl.job.core.handler.annotation.XxlJob;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.StringUtils;
//
//import java.time.Duration;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Slf4j
//public class MessageSend {
//    @XxlJob( "messageSend")
//    public ReturnT<String> messageSend( String param) throws Exception {
//        try {
//            log.info( "启动短信提醒任务" );
//            LocalDateTime nowTime = LocalDateTime.now();
//            List< ParamSmsTemplate > paramSmsTemplates = paramSmsTemplateRepository.list( new LambdaQueryWrapper< ParamSmsTemplate >().eq( ParamSmsTemplate::getDelFlag , DeleteFlagEnum.NOT_DELETE.getValue() ).eq( ParamSmsTemplate::getIsSend , "1" ) );
//            for ( ParamSmsTemplate paramSmsTemplate : paramSmsTemplates ) {
//                String customId = paramSmsTemplate.getTemplateCode();
//                if ( "1".equals( paramSmsTemplate.getSmsType() ) ) {
//                    LocalTime sendTime = paramSmsTemplate.getSSendTime();
//                    if ( sendTime == null ) {
//                        sendTime = LocalTime.of( 21 , 0 , 0 );
//                    }
//                    long beforeDays = paramSmsTemplate.getSSendBefore();
//                    if ( ! StringUtils.isEmpty( customId ) ) {
//                        if ( systemConfig.getZsCustomId().equals( customId ) ) {
//                            List< DutyScheduleInfo > dutyScheduleInfo = dutyScheduleInfoRepository.list( new LambdaQueryWrapper< DutyScheduleInfo >().in( DutyScheduleInfo::getCustomId , customId ).in( DutyScheduleInfo::getDutyType , "3" , "4" ).eq( DutyScheduleInfo::getDDay , LocalDate.now().plusDays( beforeDays ) ) );
//                            if ( ! CollectionUtils.isEmpty( dutyScheduleInfo ) ) {
//                                Duration duration = Duration.between( sendTime , nowTime.toLocalTime() );
//                                long mins = duration.toMinutes();
//                                if ( mins >= 0 && mins < 5 ) {
//
//                                    sendMessage( dutyScheduleInfo.stream().map( i -> i.getDPhone() ).collect( Collectors.toList() ) , paramSmsTemplate.getRemark() );
//                                }
//                            }
//                        }
//                        else {
//                            List< DutyScheduleInfo > dutyScheduleInfo = dutyScheduleInfoRepository.list( new LambdaQueryWrapper< DutyScheduleInfo >()
//                                    .eq( DutyScheduleInfo::getCustomId , customId )
//                                    .in( DutyScheduleInfo::getDUserjob , "科领导" , "科员" )
//                                    .eq( DutyScheduleInfo::getDutyTimesId , paramSmsTemplate.getParamDutyId() )
//                                    .eq( DutyScheduleInfo::getDDay , LocalDate.now().plusDays( beforeDays ) ) );
//                            if ( ! CollectionUtils.isEmpty( dutyScheduleInfo ) ) {
//                                Duration duration = Duration.between( sendTime , nowTime.toLocalTime() );
//                                long mins = duration.toMinutes();
//                                if ( mins >= 0 && mins < 5 ) {
//                                    sendMessage( dutyScheduleInfo.stream().map( i -> i.getDPhone() ).collect( Collectors.toList() ) , paramSmsTemplate.getRemark() );
//                                }
//                            }
//                        }
//                    }
//                }
//
//            }
//
//        } catch ( Exception e ) {
//            log.error( "短信发送功能异常" , e );
//        }
//        return ReturnT.SUCCESS;
//
//    }
//}
